package cn.teduymdj.jxc.controller;


import cn.teduymdj.jxc.myAnnotation.LogAnnotation;
import cn.teduymdj.jxc.pojo.entity.Log;
import cn.teduymdj.jxc.pojo.entity.Supplier;
import cn.teduymdj.jxc.pojo.vo.SupplierListItemVO;
import cn.teduymdj.jxc.service.SupplierService;
import cn.teduymdj.jxc.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 供应商Controller控制器
 *
 * @since 1.0
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;


    /**
     * 查询下拉框供应商信息
     *
     * @param q 供应商名称
     * @return
     */

    @LogAnnotation()
    @RequestMapping("/getComboboxList")
    public JsonResult<List<SupplierListItemVO>> getComboboxList() {

        return JsonResult.ok(supplierService.getComboboxList());

    }

    /**
     * 分页查询供应商
     *
     * @param page 当前页数
     * @param rows 每页显示的记录数
     * @param name 供应商名
     * @return
     */
    //日志保存注解,不用管:李柯辰
    @LogAnnotation(content = "分页查询供应商", type = Log.SELECT_ACTION)
    @RequestMapping("/list")
    public JsonResult<List<SupplierListItemVO>> list(Integer page, Integer rows, String name) {

        List<SupplierListItemVO> list = supplierService.getSupplierList(page, rows, name);

        return JsonResult.ok(list);
    }

    /**
     * 添加供应商
     *
     * @param supplier 供应商实体
     * @return
     */
    @LogAnnotation(content = "添加供应商", type = Log.INSERT_ACTION)
    @RequestMapping("/save")
    public JsonResult<Void> save(Supplier supplier) {

        supplierService.saveSupplier(supplier);

        return JsonResult.ok();
    }

    /**
     * 修改供应商
     *
     * @param supplier 供应商实体
     * @return
     */
    @LogAnnotation(content = "修改供应商", type = Log.UPDATE_ACTION)
    @RequestMapping("/update")
    public JsonResult<Void> update(Supplier supplier) {

        supplierService.updateSupplier(supplier);

        return JsonResult.ok();
    }

    /**
     * 删除供应商
     *
     * @param ids 供应商ids字符串，用逗号分隔
     * @return
     */
    @LogAnnotation(content = "删除供应商", type = Log.DELETE_ACTION)
    @RequestMapping("/delete")
    public JsonResult<Void> delete(Long id) {

        supplierService.deleteSupplier(id);
        return JsonResult.ok();

    }

}
